package com.cskt.common.entity.vo;

import java.io.Serializable;

/**
 * 响应结果实体类
 *
 * @author admin
 * @date 2023/04/13 15:46
 **/

public class ResultVO<T> implements Serializable {

    /**
     * 响应体状态码
     */
    private String code;
    /**
     * 响应体消息
     */
    private String msg;
    /**
     * 响应体数据
     */
    private T data;

    public static <T> ResultVO<T> ok(String code, String msg, T data) {
        return new ResultVO<>(code, msg, data);
    }

    public static <T> ResultVO<T> ok(String code, String msg) {
        return new ResultVO<>(code, msg);
    }

    public static <T> ResultVO<T> ok(T data) {
        return ok("200", "操作成功", data);
    }
    
    public static <T> ResultVO<T> ok() {
        return ok("200", "操作成功");
    }

    public static <T> ResultVO<T> error(String code, String msg) {
        return new ResultVO<>(code, msg);
    }

    public static <T> ResultVO<T> error() {
        return error("0", "操作失败");
    }

    public static <T> ResultVO<T> error(StatusEnum statusEnum) {
        return error(statusEnum.getCode(), statusEnum.getMsg());
    }

    public ResultVO() {
    }

    private ResultVO(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResultVO(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}